<template>
	<view class="evaluate-wrap">
		<view class="evaluate-main">
			<u-title value="医生信息"></u-title>
			<u-doctor-item :data="doctorDetail" :type="1"></u-doctor-item>
		</view>

		<view class="evaluate-main evaluate-mar">
			<u-title value="问诊满意度"></u-title>
			<view class="evaluate-main-rate"><uni-rate size="20" v-model="formData.star" /></view>

			<textarea placeholder-class="textarea-place" v-model="formData.content" :maxlength="1000" class="textarea-box" placeholder="问诊过程还满意吗？说说您的感受和建议吧！" />
		</view>

		<u-bottom-button value="确认评价" @click="addComment"></u-bottom-button>
	</view>
</template>

<script>
import uTitle from '@/components/u-title/u-title.vue';
import uniRate from '@/components/uni/uni-rate/uni-rate.vue';
import uDoctorItem from '@/components/u-doctor-item/u-doctor-item.vue';
import uBottomButton from '@/components/u-bottom-button/u-bottom-button.vue';
export default {
	components: {
		uTitle,
		uniRate,
		uDoctorItem,
		uBottomButton
	},
	data() {
		return {
			doctorId: null,
			doctorDetail: null,
			formData: {
				content: '',
				orderId: null,
				parentId: null,
				star: 5
			}
		};
	},
	onLoad(option) {
		this.doctorId = option.doctorId ? option.doctorId : null;
		this.formData.orderId = option.orderId ? option.orderId : null;
		this.queryDoctorDetail();
	},
	onShow() {},
	methods: {
		//医生详情
		queryDoctorDetail() {
			this.$api
				.queryDoctorDetail({
					params: {
						id: this.doctorId
					}
				})
				.then(res => {
					if (res.code == 200) {
						this.doctorDetail = res.result;
					} else {
						uni.showToast({
							title: res.message,
							icon: 'none'
						});
					}
				});
		},

		//患者添加评论
		addComment() {
			if (!this.formData.content) {
				uni.showToast({
					title: '请填写评价内容',
					icon: 'none'
				});
				return;
			}

			this.$api
				.addComment({
					data: this.formData
				})
				.then(res => {
					uni.showToast({
						title: res.message,
						icon: 'none'
					});
					if (res.code == 200) {
						uni.navigateBack({
							delta: 1
						});
					}
				});
		}
	}
};
</script>

<style lang="less">
@import './evaluate.less';
</style>
